package easy.二叉树的中序遍历;

import java.util.ArrayList;
import java.util.List;

public class Solution {
    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> result = new ArrayList<>();
        inorderHelper(root, result);
        return result;
    }

    private void inorderHelper(TreeNode node, List<Integer> result) {
        if (node == null) {
            return;
        }
        // 遍历左子树
        inorderHelper(node.left, result);
        // 访问当前节点
        result.add(node.val);
        // 遍历右子树
        inorderHelper(node.right, result);
    }

    public static void main(String[] args) {
        TreeNode root = new TreeNode(1, null, new TreeNode(2, new TreeNode(3), null));
        Solution solution = new Solution();
        System.out.println(solution.inorderTraversal(root).toString());
    }
}
